<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'invitationList.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

  </head>
  
  <style>
  		*{
  			margin:0px;
  			padding:0px;
  		}
  		table{
  			width:500px;
  			text-align:center;
  			margin:200px auto 0px;
  		}
  		tr{
  			height:40px;
  		}
  		tr:nth-of-type(even){
  			background-color:rgba(0,0,0,0.1);
  		}
  </style>
  
  <body>
  		<c:set var="ctx" value="${pageContext.request.contextPath }" />
  		<form action="${ctx }/invitation/invitationList">
  			<table border="1px" cellspacing="2px" cellpadding="0px">
  				<tr>
  					<td colspan="5"><h2>帖子列表</h2></td>
  				</tr>
  				<tr>
  					<td colspan="5">
  						<span>帖子标题：</span><input type="text" name="title" value="${title }" />
  						<input type="submit" value="提交" />
  					</td>
  				</tr>
  				<tr>
  					<td>标题</td>
  					<td>内容摘要</td>
  					<td>作者</td>
  					<td>发布时间</td>
  					<td>操作</td>
  				</tr>
  				<c:choose>
	  				<c:when test="${invitationList != null and invitationList.size()>0}">
		  				<c:forEach var="invitation" items="${invitationList }">	
		  					<tr>
		  						<td>${invitation.title }</td>
		  						<td>${invitation.summary }</td>
		  						<td>${invitation.author }</td>
		  						<td><fmt:formatDate value="${invitation.createDate }" pattern="yyyy-MM-dd"/></td>
		  						<td><a href="${ctx }/invitation/getReplyById?id=${invitation.id }">查看回复</a> || <a href="javascript:;" id="${invitation.id }" onclick="delInvitation(this)" >删除</a></td>
		  					</tr>
		  				</c:forEach>
	  				</c:when>
	  				<c:otherwise>
	  					<tr>
	  						<td colspan="5">没有查询到数据！</td>
	  					</tr>
	  				</c:otherwise>
  				</c:choose>
 				<!-- <tr class="success">
					<td colspan="5" style="color:red;">删除成功！</td>
  				</tr> -->
  				<tr>
  					<td colspan="5">
  						<a href="${ctx }/invitation/invitationList?pageIndex=1&title=${title}">首页</a>
  						<a href="${ctx }/invitation/invitationList?pageIndex=${page.pageIndex-1}&title=${title}">上一页</a>
  						<a href="${ctx }/invitation/invitationList?pageIndex=${page.pageIndex+1}&title=${title}">下一页</a>
  						<a href="${ctx }/invitation/invitationList?pageIndex=${page.totalPage}&title=${title}">末页</a>
  						<span>第${page.pageIndex }/${page.totalPage }页</span>
  					</td>
  				</tr>
  			</table>
  		</form>
  <script src="${ctx }/statics/js/jquery-1.12.4.js"></script>
  <script>
  		$(function(){
  		
  		});
  		
  		function delInvitation(obj){
			if(confirm("您确定删除该帖子及相关回复吗？")){
				$.ajax({
					url:"${ctx}/invitation/delInvitation",
					data:"id=" + $(obj).attr("id"),
					type:"get",
					dataType:"JSON",
					success:function(data){
						if(data.result == "y"){
							alert("删除成功！");
							$(obj).find("tr").remove();
							location.reload();
							/* $(".success").show(); */
						}else{
							alert("删除失败！");
						}
					},
					error:function(a,b,c){
						alert(c);
					}
				});
			}
		}
  		
  </script>
  </body>
</html>
